package com.example.demo.common;
/* @Author      zouzh
 * @PackageName BlogSystem-sm
 * @Package     com.example.demo.common
 * @Date        2023/9/6 17:29
 */

/**
 * session 工具类
 */

import com.example.demo.model.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


public class SessionUtils {
    /**
     * 得到当前登录用户
     * @param request
     * @return
     */
    public static UserInfo getUser(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(AppVar.SESSION_USERINFO_KEY) != null){
            // 登录状态
            return (UserInfo)session.getAttribute(AppVar.SESSION_USERINFO_KEY);
        }
        return null;
    }
}
